/**
 * Created by Amaris on 2016/10/9.
 */

var Waterline = require('waterline');
var uuid = require('node-uuid');
var moment = require('moment');

/**
 * @type {void|*}
 */
module.exports = Waterline.Collection.extend({
    identity: 'stockrecommend',
    tableName: 'tb_stockrecommend',
    connection: "mysql",
    attributes: {

        rowId: {
            type: 'string',
            primaryKey: true,
            unique: true,
            required: true,
            uuidv4: true,
            columnName: 'rowid',
            defaultsTo: function () {
                return uuid.v4();
            }
        },
        actionId: {
            type: 'string',
            columnName: 'actionid',
            model:'mconference'
        },
        stockName: {
            type: 'string',
            columnName: 'stock_name',
        },
        stockCode: {
            type: 'string',
            columnName: 'stock_code',
        },
        actionType: {
            type: 'string',
            required: true,
            columnName: 'actionType'
        },
        stockId: {
            type: 'string',
            required: true,
            columnName: 'stockid',
            model: 'dic_stock'
        },
        trade: {
            type: 'string',
            columnName: 'trade'
        },
        seller: {
            type: 'string',
            columnName: 'seller',
            model: 'seller'
        },
        addType: {
            type: 'string',
            columnName: 'addType'
        },
        createUid: {
            type: 'string',
            required: true,
            columnName: 'createuid',
            model: 'user'
        },
        updateTime: {
            type: 'string',
            columnName: 'updatetime'
        },
        /**
         *2017年06月19日14:50:57 新增字段
         * @returns {*|MomentObjectOutput|{years, months, date, hours, minutes, seconds, milliseconds}}
         */
        createUserId: {
            type: 'string',
            columnName: 'createuserid',
            model: 'user'
        },
        importPrice: {
            type: 'string',
            columnName: 'importprice'
        },
        expectPrice: {
            type: 'string',
            columnName: 'expectprice'
        },
        expectRate: {
            type: 'string',
            columnName: 'expectrate'
        },
        realRate: {
            type: 'string',
            columnName: 'realrate'
        },
        reason: {
            type: 'string',
            columnName: 'reason'
        },
        /**
         *是否删除，1表示正常默认为1，0表示删除
         */
        enable: {
            type: 'string',
            columnName: 'enable',
            defaultsTo:'1'
        },
        /**
         *是否是推荐的股票,1表示是推荐的股票，0表示股票池直接添加
         */
        isRecommend: {
            type: 'string',
            columnName: 'isrecommend'
        },
        /**
         * 一级股票池
         */
        parentPoolId: {
            type: 'string',
            columnName: 'parentpoolid',
            model:'stockpoolgroup'
        },
        /**
         * 二级股票池
         */
        childPoolId: {
            type: 'string',
            columnName: 'childpoolid',
            model:'stockpoolgroup'
        },
        /**
         * 附件名称
         */
        attachmentName: {
            type: 'string',
            columnName: 'attachment_name'
        },
        /**
         * 附件地址
         */
        attachmentUrl: {
            type: 'string',
            columnName: 'attachment_url'
        },
        toJSON: function () {
            var obj = this.toObject();
            obj.createdAt = moment(obj.createdAt).format('YYYY/MM/DD hh:mm');
            obj.updatedAt = moment(obj.updatedAt).format('YYYY/MM/DD hh:mm');
            return obj;
        }

    }
});
